﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using Utilities;

namespace QuartzNetService
{
    public class Quartzjob : IJob
    {
       
        /// <inheritdoc />
        /// <summary>
        /// 定时执行方法,实现Ijob
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            //业务代码
            var FilePath = $@"{ConfigurationManager.AppSettings["Log"]}{DateTime.Now:yyyy-MM-dd}.txt";
           
            System.IO.FileInfo fileinfo = new System.IO.FileInfo(("/log4net.Config"));
            log4net.Config.XmlConfigurator.Configure(fileinfo);
            JobDataMap dataMap = context.JobDetail.JobDataMap;

           
            try
            {
                using (
                    var filestream = new System.IO.FileStream(FilePath, System.IO.FileMode.Append,
                        System.IO.FileAccess.Write, FileShare.ReadWrite))
                {
                    using (var sw = new StreamWriter(filestream, Encoding.GetEncoding("gb2312")))
                    {
                        sw.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]");
                        sw.WriteLine("定时任务开始执行");
                        sw.WriteLine($"读取参数值：{dataMap.GetString("key")},{dataMap.GetString("key1")}");
                        sw.WriteLine("---------------------------------------------------------");
                        sw.Flush();
                    }
                }
               
            }
            catch (Exception e)
            {
                
                throw;
            }
        }
    }
}
